<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-04-04
 * Time: 13:47
 */

namespace app\store\service;


use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use think\Cache;


class RedGoodsService
{

    //http请求组件
    private $client;

    private $api;

    private $cache;

    /**
     * RedGoodsService constructor.
     */
    public function __construct(Client $_client,Cache $_cache)
    {
        $this->client = $_client;
        $this->cache=$_cache;
        $this->api = "http://www.zhibaoai.com/addons/ewei_shopv2/core/api";
    }

    /**
     * 预警商品信息
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function GetList()
    {
        $key='RedGoods_list';
        $data=$this->cache->get($key);
        if (!$data){
            $request = new Request('get', $this->api . '/goods/list.php?uniacid=2');
            $res = $this->client->send($request);
            $data=json_decode($res->getBody(),true);
            $this->cache->set($key,$data,600);
        }
        return $data;
    }
}